package com.edu.shiro.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.UnauthorizedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

//全局异常捕获
public class GlobalExceptionResolver implements HandlerExceptionResolver {
	
	private static Logger logger = LoggerFactory.getLogger(GlobalExceptionResolver.class);
	
	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		ModelAndView mv;
		if(ex instanceof UnauthorizedException){
			mv = new ModelAndView("/user/unauth");
			return mv;
		}else{
			mv = new ModelAndView();
			ex.printStackTrace();
			mv = new ModelAndView("/user/error");   
	        return mv;
		}
	}

}
